{template 'public/header'}
{template 'public/comhead'}
{if $operation == 'display'}

<div class="main">
<style>	
.form-control-excel {height: 34px;padding: 6px 12px;font-size: 14px;line-height: 1.42857143;color: #555;background-color: #fff;background-image: none;border: 1px solid #ccc;border-radius: 4px;-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);box-shadow: inset 0 1px 1px rgba(0,0,0,.075);-webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;-o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;}
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-primary, .bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-primary {
    color: #fff;
    background: #a0053b;
}
</style>
    <div class="panel panel-info">
        <div class="panel-heading">缴费管理</div>
        <div class="panel-body">
            <form action="./index.php" method="get" class="form-horizontal" role="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="fm_jiaoyu" />
                <input type="hidden" name="do" value="cost" />
				<input type="hidden" name="schoolid" value="{$schoolid}" />
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label" style="width: 100px;">按名称</label>
                    <div class="col-sm-2 col-lg-2">
                        <input class="form-control" name="name" id="" type="text" value="{$_GPC['name']}">
                    </div>
                    <div class="col-sm-2 col-lg-2">
                        <button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
                    </div>	
                    <div class="col-sm-2 col-lg-2">  
						<a class="btn btn-primary" href="{php echo $this->createWebUrl('cost', array('op' => 'post', 'schoolid' => $schoolid))}"><i class="fa fa-plus"></i> 添加项目</a>
						<a class="btn btn-primary" href="javascript:location.reload()"><i class="fa fa-refresh"></i>刷新</a>
					</div>	
					<div class="col-sm-2 col-lg-2">	
						<a class="btn btn-success" href="{php echo $this->createWebUrl('payall', array('op' => 'display', 'schoolid' => $schoolid))}">缴费总揽</a>
                    </div>					
				</div>			
            </form>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="table-responsive panel-body">
			<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
				<input type="hidden" name="schoolid" value="{$schoolid}" />
				<table class="table table-hover">
					<thead class="navbar-inner">
						<tr>
							<th class='with-checkbox' style="width: 20px;"><input type="checkbox" class="check_all" /></th>
							<th style="width:6%">项目名称</th>
							<th style="width:8%">是否启用</th>
							<th style="width:6%;">金额</th>
							<th style="width:5%;">适用班级</th>
							<th style="width:15%;">关联功能</th>
							<th style="width:8%;">时间限制</th>
							<th style="width:8%;">指定时间范围</th>
							<th style="width:8%;">描述</th>
							<th style="width:8%;">已付人数</th>
							<th style="text-align:right; width:8%;">操作</th>
						</tr>
					</thead>
					<tbody>
						{loop $list $item}
						<tr>
							<td class="with-checkbox"><input type="checkbox" name="check" value="{$item['id']}"></td>
							<td><a href="{php echo $this->createWebUrl('cost', array('op' => 'post', 'id' => $item['id'], 'schoolid' =>  $schoolid))}" title="管理">
								<img src="{php echo tomedia($item['icon'])}" onerror="this.src='./resource/images/nopic.jpg';" width="60px;" style="border-radius: 3px;">
								<br/>{$item['name']}</a>
							</td>
							<td><input type="checkbox" value="{$item['is_on']}" name="is_on[]" data-id="{$item['id']}" {if $item['is_on'] == 1}checked{/if}></td>
							<td>{$item['cost']}</td>	
							<td>{if empty($item['bj_id'])}<span class="label label-danger">未关联</span>{else}<span class="label label-success">已关联</span>{/if}</td>
							<td>{if !empty($item['displayorder'])}{$item['displayorder']}{else}<span class="label label-danger">未关联</span>{/if}</td>	
							<td>
							{if $item['is_time'] ==2}
								{$item['dataline']}天
							{else}
								<span class="label label-danger">未启用</span>
							{/if}	
							</td>
							<td>
							{if $item['is_time'] ==1}
								<span class="label label-info">开始</span>&nbsp;{php echo date('Y-m-d', $item['starttime'])}</br></br>
								<span class="label label-info">结束</span>&nbsp;{php echo date('Y-m-d', $item['endtime'])}
							{else}
								<span class="label label-danger">未启用</span>
							{/if}	
							</td>	
							<td>
								{if !empty($item['description'])}<span class="label label-success">有收费介绍</span>{else}<span class="label label-danger">无介绍</span>{/if}                       
							</td>							
							<td><span class="label label-success">{php echo pdo_fetchcolumn("select count(*) FROM ".tablename('wx_school_order')." WHERE costid = '".$item['id']."' And type = 3 And status =2 ")}人</span>
							<a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('payall', array('op' => 'display', 'obid' => $item['id'], 'schoolid' =>  $schoolid))}" title="查看"><i class="fa fa-qrcode">&nbsp;查看</i></a></td>
							<td style="text-align:right;">
								<a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('cost', array('id' => $item['id'], 'op' => 'post', 'schoolid' => $schoolid))}" title="编辑"><i class="fa fa-pencil"></i></a>&nbsp;&nbsp;<a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('cost', array('id' => $item['id'], 'op' => 'delete', 'schoolid' => $schoolid))}" onclick="return confirm('此操作不可恢复，确认删除？');return false;" title="删除"><i class="fa fa-times"></i></a>
							</td>
						</tr>
						{/loop}
					</tbody>
					<tr>
						<td colspan="10">
							<input name="token" type="hidden" value="{$_W['token']}" />
							<input type="button" class="btn btn-primary" name="btndeleteall" value="批量删除" />
						</td>
					</tr>
				</table>
			{$pager}
			</form>
        </div>
    </div>
</div>
<script type="text/javascript">
<!--
	var category = {php echo json_encode($children)};
//-->
$(function(){
    $(".check_all").click(function(){
        var checked = $(this).get(0).checked;
        $("input[type=checkbox]").attr("checked",checked);
    });

    $("input[name=btndeleteall]").click(function(){
        var check = $("input[type=checkbox][class!=check_all]:checked");
        if(check.length < 1){
            alert('请选择要删除的项目!');
            return false;
        }
        if(confirm("确认要删除选择的项目?")){
            var id = new Array();
            check.each(function(i){
                id[i] = $(this).val();
            });
            var url = "{php echo $this->createWebUrl('cost', array('op' => 'deleteall'))}";
            $.post(
                url,
                {idArr:id},
                function(data){
                    alert(data.error);
                    alert('操作成功!');
                },'json'
            );
        }
    });

});
</script>
<script type="text/javascript">
require(['jquery.qrcode', 'bootstrap.switch'], function($){

	$(':checkbox[name="is_on[]"]').bootstrapSwitch();
	$(':checkbox[name="is_on[]"]').on('switchChange.bootstrapSwitch', function(e, state){
		var is_on = this.checked ? 1 : 2;
		var id = $(this).data('id');
		$.post("{php echo $this->createWebUrl('cost', array('op' => 'change'))}", {is_on: is_on, id: id}, function(resp){
			setTimeout(function(){
				//location.reload();
			}, 500)
		});
	});
});
</script>
{elseif $operation == 'post'}
<div class="panel panel-info">
   <div class="panel-heading"><a class="btn btn-primary" onclick="javascript :history.back(-1);"><i class="fa fa-tasks"></i> 返回</a></div>
</div>
<div class="main">
<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
        <input type="hidden" name="id" value="{$item['id']}" />
		<input type="hidden" name="schoolid" value="{$schoolid}" />
        <div class="panel panel-default">
            <div class="panel-heading">
                添加项目
            </div>
            <div class="panel-body">
                <div class="form-group">
					<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label" style="width: 100px;">项目名称</label>
                    <div class="col-sm-9">
                        <div class="input-group">
                            <input type="text" name="name" class="form-control" value="{$item['name']}" />
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label" style="width: 100px;">图标</label>
                    <div class="col-sm-9">
                        {php echo tpl_form_field_image('icon', $item['icon'])}
                    </div>
					<div class="help-block">必须为方正图标</div>
                </div>				
				<div class="form-group">
					<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label" style="width: 100px;">缴费金额</label>
                    <div class="col-sm-9">
                        <div class="input-group">
                            <input type="text" name="cost" class="form-control" value="{$item['cost']}" />
                        </div>
                    </div>
				</div>	
				{if $_W['isfounder'] || $_W['role'] == 'owner'}
				<div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label" style="width: 100px;">付费至：</label>
                    <div class="col-sm-2 col-lg-2">
                         <div class="input-group">
							<select class="form-control" name="payweid" id="payweid">
								<option value="0">请选择收款账户</option>
								{loop $payweid $row}
								<option value="{$row['uniacid']}" {if $item['payweid']==$row['uniacid']}selected{/if}>{$row['name']}</option>
								{/loop}
							</select>
							<div class="help-block">付费至指定公众号设置的支付方式内，不设置这付费至当前公众号</div>
                         </div>
				    </div>
                </div>	
				{/if}	
				<div class="form-group">
					<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label" style="width: 100px;">选择班级</label>
					<div class="col-sm-9 col-xs-6">
						<div class="input-group text-info">
							{loop $banji $uni}
							
							{php $is = $this->uniarr($uniarr,$uni['sid']);}
									<label for="uni_{$uni['sid']}" class="checkbox-inline"><input id="uni_{$uni['sid']}" type="checkbox" name="arr[]" value="{$uni['sid']}"{if ($is)}checked="checked"{/if}> {$uni['sname']}</label>
							{/loop}
						</div>
						<div class="help-block">选择要将次项目应用到的班级</div>
					</div>
				</div>
				<div class="form-group">
                   <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label" style="width: 100px;">关联功能</label>
                        <label class="radio-inline">
                            <input type="radio" name="is_sys" value="1" {if $item['is_sys']==1}checked="true"{/if} id="credit1">是
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="is_sys" value="2" {if $item['is_sys']==2 || empty($item['is_sys'])}checked="true"{/if} id="credit0">否
                        </label>
                        <div class="help-block"></div>
                </div>
				<div id="credit-status1" {if $item['is_sys'] == 1}style="display:block"{else}style="display:none"{/if}>
					<div class="form-group">
						<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label" style="width: 100px;">关联功能</label>
						<div class="input-group">
							<select class="form-control" style="margin-right:15px;" name="about" class="form-control">
								<option value="0">请选择功能</option>
								{loop $gongneng $row}
								<option value="{$row['id']}" {if $item['about'] == $row['id']} selected="selected"{/if}>{$row['displayorder']}</option>
								{/loop}
							</select>
						</div>
					</div>	
				</div>
				<div class="form-group">
                   <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label" style="width: 100px;">计时方式</label>
                        <label class="radio-inline">
                            <input type="radio" name="is_time" value="1" {if $item['is_time']==1}checked="true"{/if} id="credit3">固定范围
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="is_time" value="2" {if $item['is_time']==2 || empty($item['is_time'])}checked="true"{/if} id="credit2">倒计时
                        </label>
						<div class="help-block">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;设置时间范围可限定本缴费关联的功能在本时间区间有效，也可以代表本缴费项目的时间区间如：书本费 2016年3月5日-2016年6月28日</div>
                        <div class="help-block">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如：基础功能使用费 2016年3月5日-2016年6月28日，到期后关联的功能将无法使用，需创建新的付费项目</div>
						<div class="help-block">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;使用范围方法,开始时间必须为设置当天,或之前,用户付费后在付费的当天开始计时，时间到期后，用户下次登录会自动生成新改新项目的未付订单</div>
                </div>	
				<div id="credit-status2" {if $item['is_time'] == 1}style="display:block"{else}style="display:none"{/if}>	
					<div class="form-group">
					   <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label" style="width: 100px;"></label>
					   <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label" style="width: 100px;">开始时间:</label>
						 <div class="col-sm-2 col-lg-2">
							<div class="input-group">
						 {if !empty($item['starttime'])}{php echo tpl_form_field_date('starttime', date('Y-m-d', $item['starttime']))}{else}{php echo tpl_form_field_date('starttime', date('Y-m-d', TIMESTAMP))}{/if}
							</div>
						 </div>
					   <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label" style="width: 100px;">结束时间:</label>
						 <div class="col-sm-2 col-lg-2">
							<div class="input-group">					 
						{if !empty($item['endtime'])}{php echo tpl_form_field_date('endtime', date('Y-m-d', $item['endtime']))}{else}{php echo tpl_form_field_date('endtime', date('Y-m-d', TIMESTAMP))}{/if}						 
							</div>
						 </div>					 
					</div>
				</div>	
				<div class="form-group">
					<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label" style="width: 100px;">时间长度</label>
					<div class="col-sm-9">
						<div class="input-group">
							<input type="text" name="dataline" class="form-control" value="{$item['dataline']}" />
						</div>
						<div class="help-block">按天计算</div>
						<div class="help-block">设置了时间范围后，此设置将无效，如果没设置，此付费项目将按付费时间开始计算，到期后关联的功能将无法使用，需创建新的付费项目，或直接修改此值</div>
					</div>
				</div>	
				<div class="form-group">
					<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label" style="width: 100px;">缴费说明</label>
					<div class="col-sm-8 col-xs-12">
						   {php echo tpl_ueditor('description', $item['description']);}
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label" style="width: 100px;">排序</label>
                    <div class="col-sm-9">
                        <div class="input-group">
                            <input type="text" name="displayorder" class="form-control" value="{$item['displayorder']}" />
                        </div>
						<div class="help-block">数值越大排序越靠前</div>
                    </div>	
                </div>				
            </div>
        </div>
        <div class="form-group col-sm-12">
            <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
            <input type="hidden" name="token" value="{$_W['token']}" />
        </div>
    </form>
</div>
<script type="text/javascript">
	var category = {php echo json_encode($children)};
//	$('#credit-status1').show();
//	$('#credit-status2').show();
	$('#credit1').click(function(){
		$('#credit-status1').show();
	});
	$('#credit0').click(function(){
		$('#credit-status1').hide();
	});
	$('#credit3').click(function(){
		$('#credit-status2').show();
	});
	$('#credit2').click(function(){
		$('#credit-status2').hide();
	});	
</script>
<script type="text/javascript">
    <!--
    var category = {php echo json_encode($children)};
    //-->
</script>
{/if}
{template 'public/footer'}